/*
 * circle.h
 *
 *  Created on: 2023骞�3鏈�31鏃�
 *      Author: 0
 */

#ifndef CODE_CIRCLE_H_
#define CODE_CIRCLE_H_

#include "zf_common_headfile.h"

#define ENCODER_PER_METER   (5800)

enum circle_type_e {
    CIRCLE_NONE = 0,                            // 前方没有圆环

    CIRCLE_LEFT_BEGIN,CIRCLE_RIGHT_BEGIN,   // 从左侧入圆环,从右侧入圆环
    CIRCLE_check_lost_line_LEFT,CIRCLE_check_lost_line_RIGHT,   // 检测丢失左线,检测丢失右线
    CIRCLE_check_find_line_LEFT,CIRCLE_check_find_line_RIGHT,   // 找到左线,找到右线
    CIRCLE_check_lost_line_again_LEFT,CIRCLE_check_lost_line_again_RIGHT, // 再次丢线

    CIRCLE_LEFT_IN,CIRCLE_RIGHT_IN,            // 进入左圆环,进入右圆环
    CIRCLE_LEFT_RUNNING,CIRCLE_RIGHT_RUNNING,  // 跑左圆环,跑右圆环
    CIRCLE_LEFT_OUT,CIRCLE_RIGHT_OUT,          // 出左圆环,出右圆环
    CIRCLE_LEFT_END,CIRCLE_RIGHT_END,          // 左圆环结束,右圆环结束
    CIRCLE_NUM, // 圆环状态数量
};

extern const char *circle_type_name[CIRCLE_NUM];

extern int cipts0[POINTS_MAX_LEN][2];
extern int cipts1[POINTS_MAX_LEN][2];
extern int cipts0_num,cipts1_num;

extern float crpts0[POINTS_MAX_LEN][2];
extern float crpts1[POINTS_MAX_LEN][2];
extern int crpts0_num, crpts1_num;

extern float crpts0b[POINTS_MAX_LEN][2];
extern float crpts1b[POINTS_MAX_LEN][2];
extern int crpts0b_num, crpts1b_num;

extern float crpts0s[POINTS_MAX_LEN][2];
extern float crpts1s[POINTS_MAX_LEN][2];
extern int crpts0s_num, crpts1s_num;

extern float crpts0a[POINTS_MAX_LEN];
extern float crpts1a[POINTS_MAX_LEN];
extern int crpts0a_num, crpts1a_num;

extern float crpts0an[POINTS_MAX_LEN];
extern float crpts1an[POINTS_MAX_LEN];
extern int crpts0an_num, crpts1an_num;

extern float crptsc0[POINTS_MAX_LEN][2];
extern float crptsc1[POINTS_MAX_LEN][2];
extern int crptsc0_num, crptsc1_num;

extern const char *circle_type_name[CIRCLE_NUM];

extern enum circle_type_e circle_type;

void check_circle(void);

void run_circle(void);

void draw_circle(void);

int ImageAddingLine (int pts[][2], int startX, int startY, int endX, int endY, int num, int pts_num);
int ImageAddingLine_kb (int pts[][2], int startX, int startY, float k, float b, int num, int pts_num);

int find_circle_corners (uint8 mode, float pts[], int pts_num, int *id);

extern float circle_end_x;
extern float circle_end_y;

extern int cx1;
extern int cy1;
extern int cx0;
extern int cy0;

#endif /* CODE_CIRCLE_H_ */
